<template>
    <div>
       <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
         <!-- 卡片列表 -->
         <el-card>
           <el-table :data="orderList" border :cell-style="{'text-align':'center'}" :header-cell-style="{'text-align':'center'}">
              <el-table-column type="index" label="#"></el-table-column>
              <el-table-column label="订单编号" prop="order_number"></el-table-column>
              <el-table-column label="订单价格" prop="order_price"></el-table-column>
              <el-table-column label="是否付款">
                <template slot-scope="scope">
                   <el-tag type="warning" v-if="scope.row.pay_status==0">未付款</el-tag>
                   <el-tag type="success" v-else >已付款</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="是否发货" prop="is_send"></el-table-column>
              <el-table-column label="下单时间">
                <template slot-scope="scope">
                  {{scope.row.create_time|formatData}}
                </template>
              </el-table-column>
              <el-table-column label="操作" >
                <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" circle @click="showAddressDialog" size="mini"></el-button>
                <el-button type="success" icon="el-icon-s-opportunity" circle @click="showProgressDialog(scope.row.order_id)" size="mini"></el-button>
                </template>
              </el-table-column>
           </el-table>
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryData.pagenum"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>

          <el-dialog
            title="修改地址"
            :visible.sync="addressDialogVisible"
            width="50%" @close="handleClose">
            <el-form :model="addressForm" ref="addressForm" :rules="addressRules" label-width="100px" >
              <el-form-item prop="infoAddress" label="省市区/县">
                <el-cascader :options="cityData" v-model="addressForm.address">
                </el-cascader>
              </el-form-item>
              <el-form-item  label="详细地址" prop="infoAddress">
                <el-input v-model="addressForm.infoAddress"></el-input>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button @click="addressDialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="editAddress">确 定</el-button>
            </span>
          </el-dialog>
          <el-dialog
            title="查看物流"
            :visible.sync="progressDialogVisible"
            width="50%" >
             <el-timeline>
              <el-timeline-item
                v-for="(item, i) in expressProgress"
                :key="i"
                :timestamp="item.ftime">
                {{item.context}}
              </el-timeline-item>
            </el-timeline>
            <span slot="footer" class="dialog-footer">
              <el-button @click="progressDialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="progressDialogVisible = false">确 定</el-button>
            </span>
          </el-dialog>
         </el-card>
    </div>
</template>

<script>
import citydata from '../assets/citydata.js';
export default {
  data() {
    return {
      queryData:{
        query:"",
        pagesize:10,
        pagenum:1
      },
      total:0,
      orderList:[],
      addressDialogVisible:false,
      addressForm:{
        infoAddress:'',
        address:[]
      },
      addressRules:{
        infoAddress:[
          { required: true, message: '请输入必填项', trigger: 'blur' }
        ]
      },
      cityData:citydata,
      progressDialogVisible:false,
      expressProgress:[]
    }
  },

  created() {
    this.getOrderList()
  },

  methods: {
    async getOrderList(){
      const {data:res}=await this.$axios.get('orders',{params:this.queryData})
      if(res.meta.status!=200) return this.$message.error('获取数据失败')
      this.total=res.data.total;
      this.orderList=res.data.goods;
      
    },
    handleSizeChange(val)
    {
     
      this.queryData.pagesize=val;
      this.getOrderList();
    },
    handleCurrentChange(val){
     
      this.queryData.pagenum=val;
      this.getOrderList();
    },
    showAddressDialog(){
      this.addressDialogVisible = true
    },
    editAddress(){
      console.log(this.addressForm.infoAddress);
      this.addressDialogVisible = false;
    },
    handleClose(){//重置修改地址form
      this.$refs.addressForm.resetFields()
    },
    async showProgressDialog(id){
      
      const {data:res}=await this.$axios.get(`/kuaidi/804909574412544580`)
      if(res.meta.status!=200) return this.$message.error('获取数据失败')
      this.expressProgress=res.data
      
      this.progressDialogVisible=true;
    }
  }
};
</script>

<style scoped lang='less'>

</style>
